package by.grsu.na.page.sample;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import by.grsu.na.app.MyWebApplication;
import by.grsu.na.dao.impl.BlackClientDao;
import by.grsu.na.dao.impl.ClientDao;
import by.grsu.na.entity.BlackClient;
import by.grsu.na.entity.Client;


public class ClientBlackPage extends WebPage {

	public ClientBlackPage(final Client client ) {
		super();


		final Form<Client> form = new Form<Client>("form", new CompoundPropertyModel<Client>(client));
		add(form);
		
		form.add(new TextField<String>("clientName"));
		form.add(new TextField<String>("clientLogin"));
		form.add(new TextField<String>("clientPasword"));


		form.add(new Link("cancel") {
			@Override
			public void onClick() {

				setResponsePage(new ClientsListPage());
			}
		});}
	
	
	
	public ClientBlackPage(final BlackClient blackClient ) {
		super();
		
		final Form<BlackClient> form = new Form<BlackClient>("form", new CompoundPropertyModel<BlackClient>(blackClient));
		add(form);
		
		
		form.add(new SubmitLink("add")
		{
			@Override
			public void onSubmit() 
			{
				super.onSubmit();

				final BlackClientDao blackClientDao = new BlackClientDao(MyWebApplication.DATA_XML_FOLDER);
				final ClientDao clientDao = new ClientDao(MyWebApplication.DATA_XML_FOLDER);
						
						if (blackClient.getId() == null) {

							blackClientDao.saveNew(blackClient);
						} else 
						{

							blackClientDao.update(blackClient);
						}
						setResponsePage(new ClientsListPage());
						
						clientDao.delete(blackClient.getId());
						
						}
			});
		}
	}
	
	
	
	
	
	
	
	
	
	
	

